package com.jiaying.patient;


import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class MultiDataEditor {
        public static void main(String[] args) {
            JFrame frame = new JFrame("主窗口");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setSize(400, 300);

            JButton editButton = new JButton("编辑数据");
            editButton.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    showMultiDataEditorDialog(frame);
                }
            });

            frame.add(editButton);
            frame.setVisible(true);
        }

        private static void showMultiDataEditorDialog(JFrame parent) {
            // 创建对话框
            JDialog dialog = new JDialog(parent, "编辑多个数据", true);
            dialog.setLayout(new GridLayout(0, 2, 10, 10));
            dialog.setSize(400, 300);

            // 添加多个编辑字段
            dialog.add(new JLabel("姓名:"));
            JTextField nameField = new JTextField();
            dialog.add(nameField);

            dialog.add(new JLabel("年龄:"));
            JTextField ageField = new JTextField();
            dialog.add(ageField);

            dialog.add(new JLabel("邮箱:"));
            JTextField emailField = new JTextField();
            dialog.add(emailField);

            // 添加按钮
            JButton saveButton = new JButton("保存");
            saveButton.addActionListener(e -> {
                // 获取所有字段值
                String name = nameField.getText();
                String age = ageField.getText();
                String email = emailField.getText();

                // 处理数据...
                JOptionPane.showMessageDialog(dialog,
                        "保存成功:\n姓名: " + name +
                                "\n年龄: " + age +
                                "\n邮箱: " + email);

                dialog.dispose();
            });

            JButton cancelButton = new JButton("取消");
            cancelButton.addActionListener(e -> dialog.dispose());

            dialog.add(saveButton);
            dialog.add(cancelButton);

            dialog.pack();
            dialog.setLocationRelativeTo(parent);
            dialog.setVisible(true);
        }
    }


